import router from './router'
import store from './store'
// import { Message } from 'element-ui'
// import NProgress from 'nprogress' // progress bar
// import 'nprogress/nprogress.css' // progress bar style
// import { getToken } from '@/utils/auth' // get token from cookie
// import getPageTitle from '@/utils/get-page-title'

// NProgress.configure({ showSpinner: false }) // NProgress Configuration

// const whiteList = ['/login'] // no redirect whitelist

router.beforeEach(async(to, from, next) => {
  if (store.state.user.token) {
    // 有token，说明已登录
    if (to.path === '/login') {
      // 还是去登录页, 就强制跳到首页
      next('/')
    } else {
      // 其他情况 放行
      next()
    }
  } else {
    // 未登录 白名单进行区分
    const whiteList = ['/login', '/404']
    if (whiteList.includes(to.path)) {
      // 存在于白名单中放行
      next()
    } else {
      // 否则跳去登录页
      next('/login')
    }
  }
})

// router.afterEach(() => {
//   // finish progress bar
//   NProgress.done()
// })
